﻿@{
    ViewBag.Title = "关联课程列表";
}
@section headerSection{
    <style>
        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-left: 5px;
        }
    </style>
}
<div class="animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins" style="margin-bottom: 0px;">
        <div class="ibox-content" style="padding: 5px 20px 0px 20px;">
            <div class="row row-lg">
                <div class="col-sm-12 col-sm-leftRight">
                    <!-- Example Toolbar -->
                    <div class="example">
                        <div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                            <button id="relAdd" type="button" class="btn btn-outline btn-primary">
                                <i class="glyphicon glyphicon-plus" aria-hidden="true">新增</i>
                            </button>
                            <button id="relDel" type="button" class="btn btn-outline btn-danger">
                                <i class="glyphicon glyphicon-trash" aria-hidden="true">删除</i>
                            </button>
                            <div class="form-group">
                                <input id="keyword" name="keyword" type="text" style="width:250px;" class="form-control" placeholder="请输入名称/path/分组">
                            </div>
                            <div class="form-group">
                                <button id="btnSearch" class="btn btn-primary" type="button"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                        </div>
                        <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true"></table>
                    </div>
                    <!-- End Example Toolbar -->
                </div>
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
</div>
@section footSection{
    <script>
        var $table, addOrEditUrl, options, store_id, store_name;
        var circleManager = {
            initPage: function () {
                if (!circleManager.initData()) {
                    layer.msg("店铺id参数异常！", { icon: 5 });
                    return false;
                }
                circleManager.initTable();
                circleManager.bindEvent();
            },
            initData: function () {
                store_id = $.getUrls('store_id');
                store_name = $.getUrls('store_name');
                if (store_name)
                    store_name = decodeURI(store_name);
                if (store_id)
                    return true;
                return false;
            },
            //1.0 初始化Table
            initTable: function () {
                options = {
                    url: ctx + "/VRCircle/InitCircleTable",
                    cutHeight: 5,
                    singleSelect:false,
                    toolbar: "#exampleToolbar",
                    queryParams: function (params) {
                        params = {
                            //页面大小
                            rows: params.limit,
                            //第几页
                            page: params.offset / params.limit + 1,
                            store_id: store_id,//店铺id
                            keyword: encodeURI($('#keyword').val()) //关键字
                        }
                        return params;
                    },
                    columns: [
                        {
                            checkbox: true
                        }, {
                            field: 'folder_order',//第一列序号
                            title: '序号',
                            align: 'center',
                            width: 50
                        }, {
                            field: 'folder_name',
                            title: '节点名称',
                            align: 'center'
                        }, {
                            field: 'pro_type',
                            title: '产品类别',
                            align: 'center',
                            formatter: function (value, row, index) {
                                switch (value) {
                                    case 1: return "VR作品"; break;
                                    case 2: return "虚仿课程"; break;
                                    case 3: return "头记"; break;
                                    case 4: return "校史馆"; break;
                                    default: return "商城"; break;
                                }
                            }
                        }, {
                            field: 'group_name',
                            title: '分组名称',
                            align: 'center'
                        }, {
                            field: 'is_recommend',
                            title: '推荐',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value)
                                    return "是";
                                return "否";
                            }
                        }, {
                            field: 'folder_path',
                            title: 'path',
                            align: 'center'
                        }, {
                            field: 'folder_note',
                            title: '备注',
                            align: 'center'
                        }, {
                            field: 'update_date',
                            title: '更新时间',
                            align: 'center'
                        }, {
                            field: 'update_name',
                            title: '更新人',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (!value)
                                    return row.create_name;
                                return value;
                            }
                        }, {
                            field: 'create_time',
                            title: '创建时间',
                            align: 'center'
                        }, {
                            field: 'create_name',
                            title: '创建人',
                            align: 'center'
                        }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            //2.0 返回选中行
            selections: function (isAll) {
                var row = $table.bootstrapTable('getSelections');
                if (!row || row.length === 0) {
                    layer.msg("数据为空或未选中记录行~", { icon: 5 });
                    return false;
                }
                if (isAll)
                    return row;
                if (row.length > 1) {
                    layer.msg("当前操作不支持多选，请选择一行再操作！", { icon: 5 });
                    return false;
                }
                return row[0];
            },
            //3.0 绑定事件
            bindEvent: function () {
                //查询
                $('#btnSearch').click(function () {
                    $table.bootstrapTable('refresh', options);
                });
                //添加
                $('#relAdd').on('click', function () {
                    var indexForm = layer.open({
                        id: 'ifreamAddCircleRel',
                        title: [store_name + '：添加关联课程', 'font-size:18px;'],
                        type: 2,
                        content: ctx + '/VRCircle/AddCircleRel?store_id=' + store_id,
                        scroll: true,//是否显示滚动条、默认不显示
                        btn: [Lang.GeneralJson.publicConfirm, Lang.GeneralJson.publicCancel],
                        area: ['95%', '98%'],
                        yes: function (li, o) {
                            //添加
                            var addData = document.getElementById("ifreamAddCircleRel").firstChild.contentWindow.circleAddManager.getCircleRelData();
                            if (addData == null)
                                return false;
                            $.ajax({
                                type: 'post',
                                url: ctx +'/VRCircle/AddStoreCourseRel',
                                data: { "store_id": store_id, "course_id": addData },
                                dataType: 'json',
                                async: false,
                                success: function (data) {
                                    if (data.Statu === 0) {
                                        layer.msg(data.Msg, { icon: 1 });
                                        layer.close(indexForm);
                                        $table.bootstrapTable('refresh', options);
                                    }
                                    if (data.Statu === 1)
                                        layer.msg(data.Msg, { icon: 5 });
                                }
                            });
                        },
                        cancel: function (li, o) { }
                    });
                });
                //删除
                $('#relDel').on('click', function () {
                    var row = circleManager.selections(true);
                    if (!row && row.length === 0)
                        return false;
                    var delId = new Array();
                    $.each(row, function (index, item) {
                        delId.push(item.id);
                    });
                    layer.confirm('您确定要删除当前选中关联课程吗？', {
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        var index = layer.msg("删除中...", { icon: 6, time: 6000 });
                        $.ajax({
                            type: 'post',
                            url: ctx + '/VRCircle/DeleteNode',
                            dataType: 'json',
                            data: {"id": delId.join(',') },
                            async: false,
                            success: function (data) {
                                layer.close(index);
                                if (data.Statu === 0) {
                                    layer.msg("删除成功...");
                                    $table.bootstrapTable('refresh', options);
                                }
                                else
                                    layer.msg(data.Msg, { icon: 5 });
                            }
                        });
                    }, function () { });
                });
            }
        }
        $(function () {
            //初始化页面
            circleManager.initPage();
        });
    </script>
}